#In order to run the summary stats, you need to run:
#- Step0-Data-prepare.R
#- Step7-Census_1895_tables.R
#- Step10-LITS_DATA_prepare.R
#- Step15_Effect_Communism_Census_1950.R
#- Step19-Habsburg_Census_jobs.R
#- Step23-Involvement in War.R


library(xtable)

setwd("/Users/bgpopescu/")
#setwd("C:/Users/bogdanp/")

#Part1
#Reading Polygons
HRV_adm0 <- st_read(dsn="./Dropbox/Legacies_Project/Analysis/data/data.gdb",
                    layer="HRV_adm0_wgs")

HRV_adm3 <- st_read(dsn="./Dropbox/Legacies_Project/Analysis/data/data.gdb",
                    layer="HRV_adm3")
HRV_adm3<-st_simplify(HRV_adm3, dTolerance = 0.005)
HRV_adm3<-subset(HRV_adm3, select = c(ID_2))
HRV_adm3_data = read_excel("./Dropbox/Legacies_Project/Analysis/data/merge.xlsx", sheet=1, col_names = TRUE, skip = 0)

final_sp<-left_join(HRV_adm3, HRV_adm3_data, by = c("ID_2"="ID_2"))
data1<-subset(final_sp, bosnia_border_mun==0)


pct_no_water <-list("Pct. Dwellings No Water, 2011", length(data1$pct_no_water[!is.na(data1$pct_no_water)]),
                    mean(data1$pct_no_water, na.rm=T),
                    min(data1$pct_no_water, na.rm=T), 
                    max(data1$pct_no_water, na.rm=T), 
                    sd(data1$pct_no_water, na.rm=T))

pct_no_sewer <-list("Pct. Dwellings No Sewer, 2011", length(data1$pct_no_sewer[!is.na(data1$pct_no_sewer)]),
                    mean(data1$pct_no_sewer, na.rm=T),
                    min(data1$pct_no_sewer, na.rm=T), 
                    max(data1$pct_no_sewer, na.rm=T), 
                    sd(data1$pct_no_sewer, na.rm=T))

pov_rate_income <-list("Pct. People at Risk of Poverty, 2011", length(data1$pov_rate_income[!is.na(data1$pov_rate_income)]),
                       mean(data1$pov_rate_income, na.rm=T),
                       min(data1$pov_rate_income, na.rm=T), 
                       max(data1$pov_rate_income, na.rm=T), 
                       sd(data1$pov_rate_income, na.rm=T))

share_lesseduc_25 <-list("Pct. Less Educated People, 2011", length(data1$share_lesseduc_25[!is.na(data1$share_lesseduc_25)]),
                         mean(data1$share_lesseduc_25, na.rm=T),
                         min(data1$share_lesseduc_25, na.rm=T), 
                         max(data1$share_lesseduc_25, na.rm=T), 
                         sd(data1$share_lesseduc_25, na.rm=T))



#Part2: Census 1895
census_1895_dist <- st_read(dsn="./Dropbox/Legacies_Project/Analysis/data/data.gdb",
                            layer="census_1895_points")
census_1895 <- subset(census_1895_dist, inside_croatia == 1)
census_1895 <- subset(census_1895, !is.na(lat) & !is.na(treat))

#Step 2: Perform calculation
census_1895$dist1 <- as.numeric( with (census_1895,ifelse(census_1895$treat==1, 1, -1)))
census_1895$krajna6_distance<-census_1895$krajna6_distance/1000
census_1895$zagreb_distance<-census_1895$zagreb_distance/1000
census_1895<-subset(census_1895, area!="*)")

census_1895$dist2 <-census_1895$dist1*census_1895$krajna6_distance
census_1895$bfe1 <- ifelse(census_1895$krajna6_NEAR_FID == 1, 1,0)
census_1895$bfe2 <- ifelse(census_1895$krajna6_NEAR_FID == 2, 1,0)
census_1895$bfe3 <- ifelse(census_1895$krajna6_NEAR_FID == 3, 1,0)
census_1895$bfe4 <- ifelse(census_1895$krajna6_NEAR_FID == 4, 1,0)
census_1895$bfe5 <- ifelse(census_1895$krajna6_NEAR_FID == 5, 1,0)
census_1895$bfe6 <- ifelse(census_1895$krajna6_NEAR_FID == 6, 1,0)
census_1895$bfe7 <- ifelse(census_1895$krajna6_NEAR_FID == 7, 1,0)
census_1895$bfe8 <- ifelse(census_1895$krajna6_NEAR_FID == 8, 1,0)

census_1895$POINT_X<-census_1895$lon
census_1895$POINT_Y<-census_1895$lat

census_1895$quad1<-ifelse((census_1895$lon > 18 & census_1895$lon< 20) & 
                            (census_1895$lat<47  & census_1895$lat>44), 1, 0)

census_1895$quad2<-ifelse((census_1895$lon > 16 & census_1895$lon< 18) & 
                            (census_1895$lat<47  & census_1895$lat>44), 1, 0)

census_1895$quad3<-ifelse((census_1895$lon > 14 & census_1895$lon< 16) & 
                            (census_1895$lat<47  & census_1895$lat>44), 1, 0)

#Creating an indicator variables for whether zadrugas exist
census_1895$zadruga_exist<-NA
census_1895$zadruga_exist[census_1895$existing_zadrugas_yokes!=0]<-1
census_1895$zadruga_exist[census_1895$existing_zadrugas_yokes==0]<-0

census_1895$log_existing_zadrugas_yokes<-log(census_1895$existing_zadrugas_yokes+1)
census_1895$prop_zadruga_from_total_area<-census_1895$existing_zadrugas_yokes/census_1895$total_area*100

census_1895$log_secretly_parted_zadrugas_yokes<-log(census_1895$secretly_parted_zadrugas_yokes + 1)
census_1895$prop_secretly_parted_zadrugas_from_total_area<-census_1895$secretly_parted_zadrugas_yokes/census_1895$total_area*100

census_1895$pop_zadrugas<-(census_1895$no_inhabitants*census_1895$existing_zadrugas_yokes)/census_1895$total_area
census_1895$pop_secret_zadrugas<-(census_1895$no_inhabitants*census_1895$secretly_parted_zadrugas_yokes)/census_1895$total_area
census_1895$log_pop_zadrugas<-log(census_1895$pop_zadrugas+1)


log_existing_zadrugas_yokes <-list("Log Area Covered by Zadrugas, 1895", length(census_1895$log_existing_zadrugas_yokes[!is.na(census_1895$log_existing_zadrugas_yokes)]),
                                   mean(census_1895$log_existing_zadrugas_yokes, na.rm=T),
                                   min(census_1895$log_existing_zadrugas_yokes, na.rm=T), 
                                   max(census_1895$log_existing_zadrugas_yokes, na.rm=T), 
                                   sd(census_1895$log_existing_zadrugas_yokes, na.rm=T))


prop_zadruga_from_total_area <-list("Pct. Area Covered by Zadrugas/Total Area, 1895", length(census_1895$prop_zadruga_from_total_area[!is.na(census_1895$prop_zadruga_from_total_area)]),
                                    mean(census_1895$prop_zadruga_from_total_area, na.rm=T),
                                    min(census_1895$prop_zadruga_from_total_area, na.rm=T), 
                                    max(census_1895$prop_zadruga_from_total_area, na.rm=T), 
                                    sd(census_1895$prop_zadruga_from_total_area, na.rm=T))


log_pop_zadrugas <-list("Log Pop. in Zadrugas, 1895", length(census_1895$log_pop_zadrugas[!is.na(census_1895$log_pop_zadrugas)]),
                        mean(census_1895$log_pop_zadrugas, na.rm=T),
                        min(census_1895$log_pop_zadrugas, na.rm=T), 
                        max(census_1895$log_pop_zadrugas, na.rm=T), 
                        sd(census_1895$log_pop_zadrugas, na.rm=T))


#Part3: LITS
lits_data = read_excel("./Dropbox/Legacies_Project/Analysis/data/data_lits.xlsx", 
                       sheet=1, col_names = TRUE, skip = 0, guess_max = 10000)


trust_people <-list("Trust People, 2006-16", length(lits_data$trust_people[!is.na(lits_data$trust_people)]),
                    mean(lits_data$trust_people, na.rm=T),
                    min(lits_data$trust_people, na.rm=T), 
                    max(lits_data$trust_people, na.rm=T), 
                    sd(lits_data$trust_people, na.rm=T))


trust_family <-list("Trust Family, 2016", length(lits_data$trust_family[!is.na(lits_data$trust_family)]),
                    mean(lits_data$trust_family, na.rm=T),
                    min(lits_data$trust_family, na.rm=T), 
                    max(lits_data$trust_family, na.rm=T), 
                    sd(lits_data$trust_family, na.rm=T))

trust_foreign_investors <-list("Trust Foreign Investors, 2006-16", length(lits_data$trust_foreign_investors[!is.na(lits_data$trust_foreign_investors)]),
                               mean(lits_data$trust_foreign_investors, na.rm=T),
                               min(lits_data$trust_foreign_investors, na.rm=T), 
                               max(lits_data$trust_foreign_investors, na.rm=T), 
                               sd(lits_data$trust_foreign_investors, na.rm=T))

trust_presidency <-list("Trust Presidency, 2006-16", length(lits_data$trust_presidency[!is.na(lits_data$trust_presidency)]),
                        mean(lits_data$trust_presidency, na.rm=T),
                        min(lits_data$trust_presidency, na.rm=T), 
                        max(lits_data$trust_presidency, na.rm=T), 
                        sd(lits_data$trust_presidency, na.rm=T))



bribery_road_police <-list("Bribery Road Police, 2006-16", length(lits_data$bribery_road_police[!is.na(lits_data$bribery_road_police)]),
                           mean(lits_data$bribery_road_police, na.rm=T),
                           min(lits_data$bribery_road_police, na.rm=T), 
                           max(lits_data$bribery_road_police, na.rm=T), 
                           sd(lits_data$bribery_road_police, na.rm=T))

bribery_unempl <-list("Bribery Unemployment, 2006-16", length(lits_data$bribery_unempl[!is.na(lits_data$bribery_unempl)]),
                      mean(lits_data$bribery_unempl, na.rm=T),
                      min(lits_data$bribery_unempl, na.rm=T), 
                      max(lits_data$bribery_unempl, na.rm=T), 
                      sd(lits_data$bribery_unempl, na.rm=T))

part_demonstr <-list("Part. Demonstration, 2006-16", length(lits_data$part_demonstr[!is.na(lits_data$part_demonstr)]),
                     mean(lits_data$part_demonstr, na.rm=T),
                     min(lits_data$part_demonstr, na.rm=T), 
                     max(lits_data$part_demonstr, na.rm=T), 
                     sd(lits_data$part_demonstr, na.rm=T))


sign_petition <-list("Sign Petition, 2016-16", length(lits_data$sign_petition[!is.na(lits_data$sign_petition)]),
                     mean(lits_data$sign_petition, na.rm=T),
                     min(lits_data$sign_petition, na.rm=T), 
                     max(lits_data$sign_petition, na.rm=T), 
                     sd(lits_data$sign_petition, na.rm=T))




elevation <-list("Elevation", length(data1$elevation[!is.na(data1$elevation)]),
                 mean(data1$elevation, na.rm=T),
                 min(data1$elevation, na.rm=T), 
                 max(data1$elevation, na.rm=T), 
                 sd(data1$elevation, na.rm=T))


slope <-list("Slope", length(data1$slope[!is.na(data1$slope)]),
             mean(data1$slope, na.rm=T),
             min(data1$slope, na.rm=T), 
             max(data1$slope, na.rm=T), 
             sd(data1$slope, na.rm=T))

tmp_mean_2010 <-list("Avg. Temperature", length(data1$tmp_mean_2010[!is.na(data1$tmp_mean_2010)]),
                     mean(data1$tmp_mean_2010, na.rm=T),
                     min(data1$tmp_mean_2010, na.rm=T), 
                     max(data1$tmp_mean_2010, na.rm=T), 
                     sd(data1$tmp_mean_2010, na.rm=T))



pre_mean_2010 <-list("Avg. Precipitation", length(data1$pre_mean_2010[!is.na(data1$pre_mean_2010)]),
                     mean(data1$pre_mean_2010, na.rm=T),
                     min(data1$pre_mean_2010, na.rm=T), 
                     max(data1$pre_mean_2010, na.rm=T), 
                     sd(data1$pre_mean_2010, na.rm=T))



maizemed <-list("Maize Suitability", length(data1$maizemed[!is.na(data1$maizemed)]),
                mean(data1$maizemed, na.rm=T),
                min(data1$maizemed, na.rm=T), 
                max(data1$maizemed, na.rm=T), 
                sd(data1$maizemed, na.rm=T))


river_total <-list("Total river in km", length(data1$river_total[!is.na(data1$river_total)]),
                   mean(data1$river_total, na.rm=T),
                   min(data1$river_total, na.rm=T), 
                   max(data1$river_total, na.rm=T), 
                   sd(data1$river_total, na.rm=T))

river_density <-list("River Density", length(data1$river_density[!is.na(data1$river_density)]),
                     mean(data1$river_density, na.rm=T),
                     min(data1$river_density, na.rm=T), 
                     max(data1$river_density, na.rm=T), 
                     sd(data1$river_density, na.rm=T))

trade_route_1450_density <-list("Trade Route Dens., 1450", length(data1$trade_route_1450_density[!is.na(data1$trade_route_1450_density)]),
                                mean(data1$trade_route_1450_density, na.rm=T),
                                min(data1$trade_route_1450_density, na.rm=T), 
                                max(data1$trade_route_1450_density, na.rm=T), 
                                sd(data1$trade_route_1450_density, na.rm=T))


trade_center_count <-list("Trade Centers, 1450", length(data1$trade_center_count[!is.na(data1$trade_center_count)]),
                          mean(data1$trade_center_count, na.rm=T),
                          min(data1$trade_center_count, na.rm=T), 
                          max(data1$trade_center_count, na.rm=T), 
                          sd(data1$trade_center_count, na.rm=T))

#Part2
census_1857 <- read_excel("./Dropbox/Legacies_Project/Analysis/data/census_1857.xlsx", sheet=1, col_names = TRUE, skip = 0)
census_1857$pct_absent_1857<-census_1857$absent/census_1857$population*100


migration_rate_1857 <-list("Pct. Out-Migration, 1857", 
                           length(census_1857$pct_absent_1857[!is.na(census_1857$pct_absent_1857)]),
                      mean(census_1857$pct_absent_1857, na.rm=T),
                      min(census_1857$pct_absent_1857, na.rm=T), 
                      max(census_1857$pct_absent_1857, na.rm=T), 
                      sd(census_1857$pct_absent_1857, na.rm=T))


migration_rate_1944 <-list("Pct. Out-Migration, 1944", 
                           length(data1$migration_rate[!is.na(data1$pct_absent_1944)]),
                           mean(data1$pct_absent_1944, na.rm=T),
                           min(data1$pct_absent_1944, na.rm=T), 
                           max(data1$pct_absent_1944, na.rm=T), 
                           sd(data1$pct_absent_1944, na.rm=T))



migration_rate <-list("Net Migration Rate, 2011", length(data1$migration_rate[!is.na(data1$migration_rate)]),
                      mean(data1$migration_rate, na.rm=T),
                      min(data1$migration_rate, na.rm=T), 
                      max(data1$migration_rate, na.rm=T), 
                      sd(data1$migration_rate, na.rm=T))

#Part3
#############
#1921 Census#
#############

census_1921 <- st_read(dsn="./Dropbox/Legacies_Project/Analysis/data/data.gdb",
                       layer="census_1921_points")


census_1921$pct_serbs_1921<-census_1921$Christian_orthodox/census_1921$Total*100
census_1921$pct_croats_1921<-census_1921$Roman_catholic/census_1921$Total*100

census_1921$dist1 <- as.numeric( with (census_1921,ifelse(census_1921$treat==1, 1, -1)))
census_1921$dist2 <-census_1921$dist1*(census_1921$krajna6_distance/1000)

census_1921$quad1<-ifelse((census_1921$lon > 18 & census_1921$lon< 20) & 
                            (census_1921$lat<47  & census_1921$lat>44), 1, 0)

census_1921$quad2<-ifelse((census_1921$lon > 16 & census_1921$lon< 18) & 
                            (census_1921$lat<47  & census_1921$lat>44), 1, 0)

census_1921$quad3<-ifelse((census_1921$lon > 14 & census_1921$lon< 16) & 
                            (census_1921$lat<47  & census_1921$lat>44), 1, 0)

census_1921$bfe1 <- ifelse(census_1921$krajna6_NEAR_FID == 1, 1,0)
census_1921$bfe2 <- ifelse(census_1921$krajna6_NEAR_FID == 2, 1,0)
census_1921$bfe3 <- ifelse(census_1921$krajna6_NEAR_FID == 3, 1,0)
census_1921$bfe4 <- ifelse(census_1921$krajna6_NEAR_FID == 4, 1,0)
census_1921$bfe5 <- ifelse(census_1921$krajna6_NEAR_FID == 5, 1,0)
census_1921$bfe6 <- ifelse(census_1921$krajna6_NEAR_FID == 6, 1,0)
census_1921$bfe7 <- ifelse(census_1921$krajna6_NEAR_FID == 7, 1,0)
census_1921$bfe8 <- ifelse(census_1921$krajna6_NEAR_FID == 8, 1,0)


census_1921$POINT_X<-census_1921$lon
census_1921$POINT_Y<-census_1921$lat
census_1921<-subset(census_1921, !is.na(treat))


#############
#1931 Census#
#############

census_1931 <- st_read(dsn="./Dropbox/Legacies_Project/Analysis/data/data.gdb",
                       layer="census_1931_points")

census_1931$pct_serbs_1931<-census_1931$Orthodox/census_1931$total*100
census_1931$pct_croats_1931<-census_1931$Roman_catholic/census_1931$total*100
census_1931$dist1 <- as.numeric( with (census_1931,ifelse(census_1931$treat==1, 1, -1)))
census_1931$dist2 <-census_1931$dist1*(census_1931$krajna6_distance/1000)
census_1931$krajna6_NEAR_FID

census_1931$quad1<-ifelse((census_1931$lon > 18 & census_1931$lon< 20) & 
                            (census_1931$lat<47  & census_1931$lat>44), 1, 0)

census_1931$quad2<-ifelse((census_1931$lon > 16 & census_1931$lon< 18) & 
                            (census_1931$lat<47  & census_1931$lat>44), 1, 0)

census_1931$quad3<-ifelse((census_1931$lon > 14 & census_1931$lon< 16) & 
                            (census_1931$lat<47  & census_1931$lat>44), 1, 0)


census_1931$bfe1 <- ifelse(census_1931$krajna6_NEAR_FID == 1, 1,0)
census_1931$bfe2 <- ifelse(census_1931$krajna6_NEAR_FID == 2, 1,0)
census_1931$bfe3 <- ifelse(census_1931$krajna6_NEAR_FID == 3, 1,0)
census_1931$bfe4 <- ifelse(census_1931$krajna6_NEAR_FID == 4, 1,0)
census_1931$bfe5 <- ifelse(census_1931$krajna6_NEAR_FID == 5, 1,0)
census_1931$bfe6 <- ifelse(census_1931$krajna6_NEAR_FID == 6, 1,0)
census_1931$bfe7 <- ifelse(census_1931$krajna6_NEAR_FID == 7, 1,0)
census_1931$bfe8 <- ifelse(census_1931$krajna6_NEAR_FID == 8, 1,0)

census_1931$POINT_X<-census_1931$lon
census_1931$POINT_Y<-census_1931$lat
census_1931<-subset(census_1931, !is.na(treat))


list_pct_serbs_1921 <-list("Pct. Serbs, 1921", length(census_1921$pct_serbs_1921[!is.na(census_1921$pct_serbs_1921)]),
                      mean(census_1921$pct_serbs_1921, na.rm=T),
                      min(census_1921$pct_serbs_1921, na.rm=T), 
                      max(census_1921$pct_serbs_1921, na.rm=T), 
                      sd(census_1921$pct_serbs_1921, na.rm=T))


list_pct_croats_1921 <-list("Pct. Croats, 1921", length(census_1921$pct_croats_1921[!is.na(census_1921$pct_croats_1921)]),
                           mean(census_1921$pct_croats_1921, na.rm=T),
                           min(census_1921$pct_croats_1921, na.rm=T), 
                           max(census_1921$pct_croats_1921, na.rm=T), 
                           sd(census_1921$pct_croats_1921, na.rm=T))




list_pct_serbs_1931 <-list("Pct. Serbs, 1931", length(census_1931$pct_serbs_1931[!is.na(census_1931$pct_serbs_1931)]),
                           mean(census_1931$pct_serbs_1931, na.rm=T),
                           min(census_1931$pct_serbs_1931, na.rm=T), 
                           max(census_1931$pct_serbs_1931, na.rm=T), 
                           sd(census_1931$pct_serbs_1931, na.rm=T))


list_pct_croats_1931 <-list("Pct. Croats, 1931", length(census_1931$pct_croats_1931[!is.na(census_1931$pct_croats_1931)]),
                           mean(census_1931$pct_croats_1931, na.rm=T),
                           min(census_1931$pct_croats_1931, na.rm=T), 
                           max(census_1931$pct_croats_1931, na.rm=T), 
                           sd(census_1931$pct_croats_1931, na.rm=T))

list_pct_serbs_1991 <-list("Pct. Serbs, 1991", length(data1$pct_serbs_1991[!is.na(data1$pct_serbs_1991)]),
                           mean(data1$pct_serbs_1991, na.rm=T),
                           min(data1$pct_serbs_1991, na.rm=T), 
                           max(data1$pct_serbs_1991, na.rm=T), 
                           sd(data1$pct_serbs_1991, na.rm=T))

list_pct_croats_1991 <-list("Pct. Croats, 1991", length(data1$pct_croats_1991[!is.na(data1$pct_croats_1991)]),
                           mean(data1$pct_croats_1991, na.rm=T),
                           min(data1$pct_croats_1991, na.rm=T), 
                           max(data1$pct_croats_1991, na.rm=T), 
                           sd(data1$pct_croats_1991, na.rm=T))

list_pct_serbs_2001 <-list("Pct. Serbs, 2001", length(data1$Pct_Serbs_2001[!is.na(data1$Pct_Serbs_2001)]),
                           mean(data1$Pct_Serbs_2001, na.rm=T),
                           min(data1$Pct_Serbs_2001, na.rm=T), 
                           max(data1$Pct_Serbs_2001, na.rm=T), 
                           sd(data1$Pct_Serbs_2001, na.rm=T))

list_pct_croats_2001 <-list("Pct. Croats, 2001", length(data1$Pct_Croats_2001[!is.na(data1$Pct_Croats_2001)]),
                           mean(data1$Pct_Croats_2001, na.rm=T),
                           min(data1$Pct_Croats_2001, na.rm=T), 
                           max(data1$Pct_Croats_2001, na.rm=T), 
                           sd(data1$Pct_Croats_2001, na.rm=T))


list_pct_change_serbs <-list("Change, '91-'01", length(data1$pct_change_serbs[!is.na(data1$pct_change_serbs)]),
                           mean(data1$pct_change_serbs, na.rm=T),
                           min(data1$pct_change_serbs, na.rm=T), 
                           max(data1$pct_change_serbs, na.rm=T), 
                           sd(data1$pct_change_serbs, na.rm=T))


list_pct_change_croats <-list("Change, '91-'01", length(data1$pct_change_croats[!is.na(data1$pct_change_croats)]),
                             mean(data1$pct_change_croats, na.rm=T),
                             min(data1$pct_change_croats, na.rm=T), 
                             max(data1$pct_change_croats, na.rm=T), 
                             sd(data1$pct_change_croats, na.rm=T))


list_pct_serbs_2011 <-list("Pct. Serbs, 2011", length(data1$Pct_Serbs[!is.na(data1$Pct_Serbs)]),
                              mean(data1$Pct_Serbs, na.rm=T),
                              min(data1$Pct_Serbs, na.rm=T), 
                              max(data1$Pct_Serbs, na.rm=T), 
                              sd(data1$Pct_Serbs, na.rm=T))

list_pct_croats_2011 <-list("Pct. Croats, 2011", length(data1$Pct_Croats[!is.na(data1$Pct_Croats)]),
                           mean(data1$Pct_Croats, na.rm=T),
                           min(data1$Pct_Croats, na.rm=T), 
                           max(data1$Pct_Croats, na.rm=T), 
                           sd(data1$Pct_Croats, na.rm=T))


list_pct_priests_1857 <-list("Pct. Priests, 1857", length(census_1857$pct_priests[!is.na(census_1857$pct_priests)]),
                            mean(census_1857$pct_priests, na.rm=T),
                            min(census_1857$pct_priests, na.rm=T), 
                            max(census_1857$pct_priests, na.rm=T), 
                            sd(census_1857$pct_priests, na.rm=T))

list_pct_civil_servants_1857 <-list("Pct. Civil Servants, 1857", length(census_1857$pct_civil_servants[!is.na(census_1857$pct_civil_servants)]),
                             mean(census_1857$pct_civil_servants, na.rm=T),
                             min(census_1857$pct_civil_servants, na.rm=T), 
                             max(census_1857$pct_civil_servants, na.rm=T), 
                             sd(census_1857$pct_civil_servants, na.rm=T))


list_pct_military_1857 <-list("Pct. Military, 1857", length(census_1857$pct_military[!is.na(census_1857$pct_military)]),
                                    mean(census_1857$pct_military, na.rm=T),
                                    min(census_1857$pct_military, na.rm=T), 
                                    max(census_1857$pct_military, na.rm=T), 
                                    sd(census_1857$pct_military, na.rm=T))

list_pct_military_1857 <-list("Pct. Writers and Artists, 1857", length(census_1857$pct_writers_artists[!is.na(census_1857$pct_writers_artists)]),
                              mean(census_1857$pct_writers_artists, na.rm=T),
                              min(census_1857$pct_writers_artists, na.rm=T), 
                              max(census_1857$pct_writers_artists, na.rm=T), 
                              sd(census_1857$pct_writers_artists, na.rm=T))

list_pct_lawyers_1857 <-list("Pct. Lawyers, 1857", length(census_1857$pct_lawyers[!is.na(census_1857$pct_lawyers)]),
                              mean(census_1857$pct_lawyers, na.rm=T),
                              min(census_1857$pct_lawyers, na.rm=T), 
                              max(census_1857$pct_lawyers, na.rm=T), 
                              sd(census_1857$pct_lawyers, na.rm=T))

list_pct_doctors_1857 <-list("Pct. Doctors, 1857", length(census_1857$pct_doctors[!is.na(census_1857$pct_doctors)]),
                             mean(census_1857$pct_doctors, na.rm=T),
                             min(census_1857$pct_doctors, na.rm=T), 
                             max(census_1857$pct_doctors, na.rm=T), 
                             sd(census_1857$pct_doctors, na.rm=T))


list_pct_manufacturers_1857 <-list("Pct. Manufacturers, 1857", length(census_1857$pct_manufacturer[!is.na(census_1857$pct_manufacturer)]),
                             mean(census_1857$pct_manufacturer, na.rm=T),
                             min(census_1857$pct_manufacturer, na.rm=T), 
                             max(census_1857$pct_manufacturer, na.rm=T), 
                             sd(census_1857$pct_manufacturer, na.rm=T))



list_pct_merchants_1857 <-list("Pct. Merchants, 1857", length(census_1857$pct_merchants[!is.na(census_1857$pct_merchants)]),
                                   mean(census_1857$pct_merchants, na.rm=T),
                                   min(census_1857$pct_merchants, na.rm=T), 
                                   max(census_1857$pct_merchants, na.rm=T), 
                                   sd(census_1857$pct_merchants, na.rm=T))


list_pct_fishermen_1857 <-list("Pct. Fishermen, 1857", length(census_1857$pct_fishermen[!is.na(census_1857$pct_fishermen)]),
                               mean(census_1857$pct_fishermen, na.rm=T),
                               min(census_1857$pct_fishermen, na.rm=T), 
                               max(census_1857$pct_fishermen, na.rm=T), 
                               sd(census_1857$pct_fishermen, na.rm=T))

list_pct_agriculture_1857 <-list("Pct. Agriculture, 1857", length(census_1857$pct_agriculture[!is.na(census_1857$pct_agriculture)]),
                               mean(census_1857$pct_agriculture, na.rm=T),
                               min(census_1857$pct_agriculture, na.rm=T), 
                               max(census_1857$pct_agriculture, na.rm=T), 
                               sd(census_1857$pct_agriculture, na.rm=T))


list_pct_worker_crafts_1857 <-list("Pct. Workers Crafts, 1857", length(census_1857$pct_worker_crafts[!is.na(census_1857$pct_worker_crafts)]),
                                 mean(census_1857$pct_worker_crafts, na.rm=T),
                                 min(census_1857$pct_worker_crafts, na.rm=T), 
                                 max(census_1857$pct_worker_crafts, na.rm=T), 
                                 sd(census_1857$pct_worker_crafts, na.rm=T))


list_pct_worker_trade_1857 <-list("Pct. Workers Trade, 1857", length(census_1857$pct_worker_trade[!is.na(census_1857$pct_worker_trade)]),
                                   mean(census_1857$pct_worker_trade, na.rm=T),
                                   min(census_1857$pct_worker_trade, na.rm=T), 
                                   max(census_1857$pct_worker_trade, na.rm=T), 
                                   sd(census_1857$pct_worker_trade, na.rm=T))

list_pct_day_workes_1857 <-list("Pct. Day Workers, 1857", length(census_1857$pct_day_laborers[!is.na(census_1857$pct_day_laborers)]),
                                  mean(census_1857$pct_day_laborers, na.rm=T),
                                  min(census_1857$pct_day_laborers, na.rm=T), 
                                  max(census_1857$pct_day_laborers, na.rm=T), 
                                  sd(census_1857$pct_day_laborers, na.rm=T))


pct_military_1857 <-list("Pct. Military, 1857", length(data1$pct_military_1857[!is.na(data1$pct_military_1857)]),
                         mean(data1$pct_military_1857, na.rm=T),
                         min(data1$pct_military_1857, na.rm=T), 
                         max(data1$pct_military_1857, na.rm=T), 
                         sd(data1$pct_military_1857, na.rm=T))


pop_zadruga_1895 <-list("Pop. in Zadruga, 1895", length(data1$pop_zadrugas[!is.na(data1$pop_zadrugas)]),
                         mean(data1$pop_zadrugas, na.rm=T),
                         min(data1$pop_zadrugas, na.rm=T), 
                         max(data1$pop_zadrugas, na.rm=T), 
                         sd(data1$pop_zadrugas, na.rm=T))



list_railroads_1869_density <-list("Density Railroads, 1869", length(data1$Pct_Croats[!is.na(data1$railroads_1869_density)]),
                                   mean(data1$railroads_1869_density, na.rm=T),
                                   min(data1$railroads_1869_density, na.rm=T), 
                                   max(data1$railroads_1869_density, na.rm=T), 
                                   sd(data1$railroads_1869_density, na.rm=T))


list_market_places <-list("No. Marketplaces, 1857", length(data1$marketplaces[!is.na(data1$marketplaces)]),
                                   mean(data1$marketplaces, na.rm=T),
                                   min(data1$marketplaces, na.rm=T), 
                                   max(data1$marketplaces, na.rm=T), 
                                   sd(data1$marketplaces, na.rm=T))


list_rat_lawyers_notaries_1857 <-list("Prop. Lawyers and Noraties, 1857", length(data1$rat_lawyers_notaries_1857[!is.na(data1$rat_lawyers_notaries_1857)]),
                          mean(data1$rat_lawyers_notaries_1857, na.rm=T),
                          min(data1$rat_lawyers_notaries_1857, na.rm=T), 
                          max(data1$rat_lawyers_notaries_1857, na.rm=T), 
                          sd(data1$rat_lawyers_notaries_1857, na.rm=T))

list_rat_medical_personel_1857 <-list("Prop. Doctors, 1857", length(data1$rat_medical_personel_1857[!is.na(data1$rat_medical_personel_1857)]),
                                 mean(data1$rat_medical_personel_1857, na.rm=T),
                                 min(data1$rat_medical_personel_1857, na.rm=T), 
                                 max(data1$rat_medical_personel_1857, na.rm=T), 
                                 sd(data1$rat_medical_personel_1857, na.rm=T))


list_railroads_1869_density <-list("Railroad Density, 1869", length(data1$railroads_1869_density[!is.na(data1$railroads_1869_density)]),
                                      mean(data1$railroads_1869_density, na.rm=T),
                                      min(data1$railroads_1869_density, na.rm=T), 
                                      max(data1$railroads_1869_density, na.rm=T), 
                                      sd(data1$railroads_1869_density, na.rm=T))


list_planned_railroads_1869_density <-list("Planned Railroad Density, 1869", length(data1$planned_railroads_1869_density[!is.na(data1$planned_railroads_1869_density)]),
                                   mean(data1$planned_railroads_1869_density, na.rm=T),
                                   min(data1$planned_railroads_1869_density, na.rm=T), 
                                   max(data1$planned_railroads_1869_density, na.rm=T), 
                                   sd(data1$planned_railroads_1869_density, na.rm=T))

list_planned_railroads_1884_density <-list("Planned Railroad Density, 1884", length(data1$planned_railroads_1884_density[!is.na(data1$planned_railroads_1884_density)]),
                                           mean(data1$planned_railroads_1884_density, na.rm=T),
                                           min(data1$planned_railroads_1884_density, na.rm=T), 
                                           max(data1$planned_railroads_1884_density, na.rm=T), 
                                           sd(data1$planned_railroads_1884_density, na.rm=T))


list_thoroughfare_1940_density <-list("Thoroughfare Density, 1940", length(data1$thoroughfare_1940_density[!is.na(data1$thoroughfare_1940_density)]),
                                           mean(data1$thoroughfare_1940_density, na.rm=T),
                                           min(data1$thoroughfare_1940_density, na.rm=T), 
                                           max(data1$thoroughfare_1940_density, na.rm=T), 
                                           sd(data1$thoroughfare_1940_density, na.rm=T))


list_roads_1957_concrete_density <- list("Asphalt Road Density, 1957", length(data1$roads_1957_concrete_density[!is.na(data1$roads_1957_concrete_density)]),
                                           mean(data1$roads_1957_concrete_density, na.rm=T),
                                           min(data1$roads_1957_concrete_density, na.rm=T), 
                                           max(data1$roads_1957_concrete_density, na.rm=T), 
                                           sd(data1$roads_1957_concrete_density, na.rm=T))



list_road_residential_density <- list("Residential Road Density, 2017", length(data1$road_residential_density[!is.na(data1$road_residential_density)]),
                                         mean(data1$road_residential_density, na.rm=T),
                                         min(data1$road_residential_density, na.rm=T), 
                                         max(data1$road_residential_density, na.rm=T), 
                                         sd(data1$road_residential_density, na.rm=T))


list_road_track_density <- list("Road Track Density, 2017", length(data1$road_track_density[!is.na(data1$road_track_density)]),
                                      mean(data1$road_track_density, na.rm=T),
                                      min(data1$road_track_density, na.rm=T), 
                                      max(data1$road_track_density, na.rm=T), 
                                      sd(data1$road_track_density, na.rm=T))



log_ww2_bombs_no <-list("Log No. WW2 Bombs, 1939-45", length(data1$log_ww2_bombs_no[!is.na(data1$log_ww2_bombs_no)]),
                        mean(data1$log_ww2_bombs_no, na.rm=T),
                        min(data1$log_ww2_bombs_no, na.rm=T), 
                        max(data1$log_ww2_bombs_no, na.rm=T), 
                        sd(data1$log_ww2_bombs_no, na.rm=T))

log_tons_TNT <-list("Log Tons TNT WW2, 1939-45", length(data1$log_tons_TNT[!is.na(data1$log_tons_TNT)]),
                    mean(data1$log_tons_TNT, na.rm=T),
                    min(data1$log_tons_TNT, na.rm=T), 
                    max(data1$log_tons_TNT, na.rm=T), 
                    sd(data1$log_tons_TNT, na.rm=T))


log_con_camp_no <-list("Log Concentr. Camp Count, 1944", length(data1$log_con_camp_no[!is.na(data1$log_con_camp_no)]),
                       mean(data1$log_con_camp_no, na.rm=T),
                       min(data1$log_con_camp_no, na.rm=T), 
                       max(data1$log_con_camp_no, na.rm=T), 
                       sd(data1$log_con_camp_no, na.rm=T))

log_con_camp_prisoners <-list("Log Concentr. Camp prisoners, 1944", length(data1$log_con_camp_prisoners[!is.na(data1$log_con_camp_prisoners)]),
                              mean(data1$log_con_camp_prisoners, na.rm=T),
                              min(data1$log_con_camp_prisoners, na.rm=T), 
                              max(data1$log_con_camp_prisoners, na.rm=T), 
                              sd(data1$log_con_camp_prisoners, na.rm=T))


log_massacre_death_no <-list("Log Massacre Death Count, 1944", length(data1$log_massacre_death_no[!is.na(data1$log_massacre_death_no)]),
                             mean(data1$log_massacre_death_no, na.rm=T),
                             min(data1$log_massacre_death_no, na.rm=T), 
                             max(data1$log_massacre_death_no, na.rm=T), 
                             sd(data1$log_massacre_death_no, na.rm=T))

#Part x
census_1950<-read_excel("./Dropbox/Legacies_Project/Analysis/data/census_1950.xlsx",
                        sheet=1, col_names = TRUE, skip = 0)


zadrugas_total <-list("Total Cooperatives, 1950", length(census_1950$zadrugas_total[!is.na(census_1950$zadrugas_total)]),
                      mean(census_1950$zadrugas_total, na.rm=T),
                      min(census_1950$zadrugas_total, na.rm=T), 
                      max(census_1950$zadrugas_total, na.rm=T), 
                      sd(census_1950$zadrugas_total, na.rm=T))

households_with_no_zadruga_member <-list("Households with No Cooperative Members, 1950", length(census_1950$households_with_no_zadruga_member[!is.na(census_1950$households_with_no_zadruga_member)]),
                                         mean(census_1950$households_with_no_zadruga_member, na.rm=T),
                                         min(census_1950$households_with_no_zadruga_member, na.rm=T), 
                                         max(census_1950$households_with_no_zadruga_member, na.rm=T), 
                                         sd(census_1950$households_with_no_zadruga_member, na.rm=T))


coop_machines_plows_all_kinds <-list("Cooperative Plows, 1950", length(census_1950$coop_machines_plows_all_kinds[!is.na(census_1950$coop_machines_plows_all_kinds)]),
                                     mean(census_1950$coop_machines_plows_all_kinds, na.rm=T),
                                     min(census_1950$coop_machines_plows_all_kinds, na.rm=T), 
                                     max(census_1950$coop_machines_plows_all_kinds, na.rm=T), 
                                     sd(census_1950$coop_machines_plows_all_kinds, na.rm=T))




q925a <-list("Torture Oneself", length(lits_data$q925a[!is.na(lits_data$q925a)]),
             mean(lits_data$q925a, na.rm=T),
             min(lits_data$q925a, na.rm=T), 
             max(lits_data$q925a, na.rm=T), 
             sd(lits_data$q925a, na.rm=T))


q925c <-list("Torture Grandparents", length(lits_data$q925c[!is.na(lits_data$q925c)]),
             mean(lits_data$q925c, na.rm=T),
             min(lits_data$q925c, na.rm=T), 
             max(lits_data$q925c, na.rm=T), 
             sd(lits_data$q925c, na.rm=T))


Sum_deaths <-list("No. of Deaths", length(data1$Sum_best[!is.na(data1$Sum_best)]),
                     mean(data1$Sum_best, na.rm=T),
                     min(data1$Sum_best, na.rm=T), 
                     max(data1$Sum_best, na.rm=T), 
                     sd(data1$Sum_best, na.rm=T))


Sum_buildings <-list("Yug. Wars Blds. Damaged, 1991-01", length(data1$Sum_buildings[!is.na(data1$Sum_buildings)]),
                     mean(data1$Sum_buildings, na.rm=T),
                     min(data1$Sum_buildings, na.rm=T), 
                     max(data1$Sum_buildings, na.rm=T), 
                     sd(data1$Sum_buildings, na.rm=T))


Sum_minor_dam_1 <-list("Light Damage 1", length(data1$Sum_minor_dam_1[!is.na(data1$Sum_minor_dam_1)]),
                       mean(data1$Sum_minor_dam_1, na.rm=T),
                       min(data1$Sum_minor_dam_1, na.rm=T), 
                       max(data1$Sum_minor_dam_1, na.rm=T), 
                       sd(data1$Sum_minor_dam_1, na.rm=T))


Sum_light_dam_constr_2 <-list("Light Damage 2", length(data1$Sum_light_dam_constr_2[!is.na(data1$Sum_light_dam_constr_2)]),
                              mean(data1$Sum_light_dam_constr_2, na.rm=T),
                              min(data1$Sum_light_dam_constr_2, na.rm=T), 
                              max(data1$Sum_light_dam_constr_2, na.rm=T), 
                              sd(data1$Sum_light_dam_constr_2, na.rm=T))


Sum_light_dam_port_3 <-list("Light Damage 3", length(data1$Sum_light_dam_port_3[!is.na(data1$Sum_light_dam_port_3)]),
                            mean(data1$Sum_light_dam_port_3, na.rm=T),
                            min(data1$Sum_light_dam_port_3, na.rm=T), 
                            max(data1$Sum_light_dam_port_3, na.rm=T), 
                            sd(data1$Sum_light_dam_port_3, na.rm=T))

Sum_serious_dam_4 <-list("Serious Damage 4", length(data1$Sum_serious_dam_4[!is.na(data1$Sum_serious_dam_4)]),
                         mean(data1$Sum_serious_dam_4, na.rm=T),
                         min(data1$Sum_serious_dam_4, na.rm=T), 
                         max(data1$Sum_serious_dam_4, na.rm=T), 
                         sd(data1$Sum_serious_dam_4, na.rm=T))


Sum_build_part_destr_5 <-list("Partial Destr. 5", length(data1$Sum_build_part_destr_5[!is.na(data1$Sum_build_part_destr_5)]),
                              mean(data1$Sum_build_part_destr_5, na.rm=T),
                              min(data1$Sum_build_part_destr_5, na.rm=T), 
                              max(data1$Sum_build_part_destr_5, na.rm=T), 
                              sd(data1$Sum_build_part_destr_5, na.rm=T))

Sum_build_compl_dam_6 <-list("Complete Destr. 6", length(data1$Sum_build_compl_dam_6[!is.na(data1$Sum_build_compl_dam_6)]),
                             mean(data1$Sum_build_compl_dam_6, na.rm=T),
                             min(data1$Sum_build_compl_dam_6, na.rm=T), 
                             max(data1$Sum_build_compl_dam_6, na.rm=T), 
                             sd(data1$Sum_build_compl_dam_6, na.rm=T))

Sum_buildings <-list("Buildings", length(data1$Sum_buildings[!is.na(data1$Sum_buildings)]),
                     mean(data1$Sum_buildings, na.rm=T),
                     min(data1$Sum_buildings, na.rm=T), 
                     max(data1$Sum_buildings, na.rm=T), 
                     sd(data1$Sum_buildings, na.rm=T))

Sum_church_faith_places <-list("Churches", length(data1$Sum_church_faith_places[!is.na(data1$Sum_church_faith_places)]),
                               mean(data1$Sum_church_faith_places, na.rm=T),
                               min(data1$Sum_church_faith_places, na.rm=T), 
                               max(data1$Sum_church_faith_places, na.rm=T), 
                               sd(data1$Sum_church_faith_places, na.rm=T))


Sum_schools_hotels <-list("Schools, Hotels", length(data1$Sum_schools_hotels[!is.na(data1$Sum_schools_hotels)]),
                          mean(data1$Sum_schools_hotels, na.rm=T),
                          min(data1$Sum_schools_hotels, na.rm=T), 
                          max(data1$Sum_schools_hotels, na.rm=T), 
                          sd(data1$Sum_schools_hotels, na.rm=T))


Sum_monuments_symbols <-list("Monuments", length(data1$Sum_monuments_symbols[!is.na(data1$Sum_monuments_symbols)]),
                             mean(data1$Sum_monuments_symbols, na.rm=T),
                             min(data1$Sum_monuments_symbols, na.rm=T), 
                             max(data1$Sum_monuments_symbols, na.rm=T), 
                             sd(data1$Sum_monuments_symbols, na.rm=T))


q924a <-list("Injury WW2", length(lits_data$q924a[!is.na(lits_data$q924a)]),
             mean(lits_data$q924a, na.rm=T),
             min(lits_data$q924a, na.rm=T), 
             max(lits_data$q924a, na.rm=T), 
             sd(lits_data$q924a, na.rm=T))

q924b <-list("Had to Move during Move WW2", length(lits_data$q924b[!is.na(lits_data$q924b)]),
             mean(lits_data$q924b, na.rm=T),
             min(lits_data$q924b, na.rm=T), 
             max(lits_data$q924b, na.rm=T), 
             sd(lits_data$q924b, na.rm=T))

q924c <-list("Injury during Yug. Confl.", length(lits_data$q924c[!is.na(lits_data$q924c)]),
             mean(lits_data$q924c, na.rm=T),
             min(lits_data$q924c, na.rm=T), 
             max(lits_data$q924c, na.rm=T), 
             sd(lits_data$q924c, na.rm=T))


bosnia_distance <-list("Distance from Bosnia and Serbia", length(data1$bosnia_distance[!is.na(data1$bosnia_distance)]),
                       mean(data1$bosnia_distance, na.rm=T),
                       min(data1$bosnia_distance, na.rm=T), 
                       max(data1$bosnia_distance, na.rm=T), 
                       sd(data1$bosnia_distance, na.rm=T))



road_density_2022 <-list("Road Density, 2022", length(data1$road_density_2022[!is.na(data1$road_density_2022)]),
                       mean(data1$road_density_2022, na.rm=T),
                       min(data1$road_density_2022, na.rm=T), 
                       max(data1$road_density_2022, na.rm=T), 
                       sd(data1$road_density_2022, na.rm=T))



#Part x
census_1921$eth_frac_1921<-1-((census_1921$Serb_or_Croat/census_1921$Total)^2+
                                (census_1921$Slovenian/census_1921$Total)^2+
                                (census_1921$Czech/census_1921$Total)^2+
                                (census_1921$Rusyn/census_1921$Total)^2+
                                (census_1921$Pole/census_1921$Total)^2+
                                (census_1921$Russian/census_1921$Total)^2+
                                (census_1921$Hungarian/census_1921$Total)^2+
                                (census_1921$German/census_1921$Total)^2+
                                (census_1921$Albanian/census_1921$Total)^2+
                                (census_1921$Turk/census_1921$Total)^2+
                                (census_1921$Romanian/census_1921$Total)^2+
                                (census_1921$Italian/census_1921$Total)^2+
                                (census_1921$French/census_1921$Total)^2+
                                (census_1921$English/census_1921$Total)^2+
                                (census_1921$Other_and_unknown/census_1921$Total)^2)


eth_frac_1921 <-list("Ethnic Fractionalization, 1921", length(census_1921$eth_frac_1921[!is.na(census_1921$eth_frac_1921)]),
                     mean(census_1921$eth_frac_1921, na.rm=T),
                     min(census_1921$eth_frac_1921, na.rm=T), 
                     max(census_1921$eth_frac_1921, na.rm=T), 
                     sd(census_1921$eth_frac_1921, na.rm=T))


census_1931$eth_frac_1931<-1-((census_1931$Orthodox/census_1931$total)^2+
                                (census_1931$Roman_catholic/census_1931$total)^2+
                                (census_1931$Protestant/census_1931$total)^2+
                                (census_1931$Other_christian/census_1931$total)^2+
                                (census_1931$Muslim/census_1931$total)^2+
                                (census_1931$no_confession_or_unknown/census_1931$total)^2)


eth_frac_1931 <-list("Ethnic Fractionalization, 1931", length(census_1931$eth_frac_1931[!is.na(census_1931$eth_frac_1931)]),
                     mean(census_1931$eth_frac_1931, na.rm=T),
                     min(census_1931$eth_frac_1931, na.rm=T), 
                     max(census_1931$eth_frac_1931, na.rm=T), 
                     sd(census_1931$eth_frac_1931, na.rm=T))



eth_frac_1991 <-list("Ethnic Fractionalization, 1991", length(data1$eth_frac_1991[!is.na(data1$eth_frac_1991)]),
                     mean(data1$eth_frac_1991, na.rm=T),
                     min(data1$eth_frac_1991, na.rm=T), 
                     max(data1$eth_frac_1991, na.rm=T), 
                     sd(data1$eth_frac_1991, na.rm=T))

eth_frac_2001 <-list("Ethnic Fractionalization, 2001", length(data1$eth_frac_2001[!is.na(data1$eth_frac_2001)]),
                     mean(data1$eth_frac_2001, na.rm=T),
                     min(data1$eth_frac_2001, na.rm=T), 
                     max(data1$eth_frac_2001, na.rm=T), 
                     sd(data1$eth_frac_2001, na.rm=T))

eth_frac_2011 <-list("Ethnic Fractionalization, 2011", length(data1$eth_frac_2011[!is.na(data1$eth_frac_2011)]),
                     mean(data1$eth_frac_2011, na.rm=T),
                     min(data1$eth_frac_2011, na.rm=T), 
                     max(data1$eth_frac_2011, na.rm=T), 
                     sd(data1$eth_frac_2011, na.rm=T))


transparency <-list("Local Gvt. Budget Transparency, 2016", length(data1$transparency[!is.na(data1$transparency)]),
                    mean(data1$transparency, na.rm=T),
                    min(data1$transparency, na.rm=T), 
                    max(data1$transparency, na.rm=T), 
                    sd(data1$transparency, na.rm=T))



pct_amred_forces_1857 <-list("Pct. Armed Forces, 1857", length(census_1857$pct_military[!is.na(census_1857$pct_military)]),
                             mean(census_1857$pct_military, na.rm=T),
                             min(census_1857$pct_military, na.rm=T), 
                             max(census_1857$pct_military, na.rm=T), 
                             sd(census_1857$pct_military, na.rm=T))

#Part x
census_1900 = read_excel("./Dropbox/Legacies_Project/Analysis/data/census_1900_military.xlsx", 
                                   sheet="Volume1", col_names = TRUE, skip = 2)
census_1900$pct_military_1900<-census_1900$military_present/census_1900$total_people*100

pct_military_1900 <-list("Pct. Armed Forces, 1900", length(census_1900$pct_military_1900[!is.na(census_1900$pct_military_1900)]),
                             mean(census_1900$pct_military_1900, na.rm=T),
                             min(census_1900$pct_military_1900, na.rm=T), 
                             max(census_1900$pct_military_1900, na.rm=T), 
                             sd(census_1900$pct_military_1900, na.rm=T))


census_1910 = read_excel("./Dropbox/Legacies_Project/Analysis/data/census_1910_military.xlsx", 
                                   sheet='Volume1', col_names = TRUE, skip = 2)
census_1910$pct_military_1910<-census_1910$military_present/census_1910$total_people*100

pct_military_1910 <-list("Pct. Armed Forces, 1910", length(census_1910$pct_military_1910[!is.na(census_1910$pct_military_1910)]),
                         mean(census_1910$pct_military_1910, na.rm=T),
                         min(census_1910$pct_military_1910, na.rm=T), 
                         max(census_1910$pct_military_1910, na.rm=T), 
                         sd(census_1910$pct_military_1910, na.rm=T))


census_1931<-read_excel("./Dropbox/Legacies_Project/Data/historical_censuses/census_1931/census_1931_srez.xlsx",
                              sheet=1, col_names = TRUE, skip = 0)
census_1931$pubserv_bureaucrats_pct<-census_1931$pubserv_bureaucrats/census_1931$pubserv_all*100


pct_military_1930 <-list("Pct. Armed Forces, 1931", length(census_1931$pubserv_bureaucrats_pct[!is.na(census_1931$pubserv_bureaucrats_pct)]),
                         mean(census_1931$pubserv_bureaucrats_pct, na.rm=T),
                         min(census_1931$pubserv_bureaucrats_pct, na.rm=T), 
                         max(census_1931$pubserv_bureaucrats_pct, na.rm=T), 
                         sd(census_1931$pubserv_bureaucrats_pct, na.rm=T))



pct_amred_forces_1991 <-list("Pct. Armed Forces, 1991", length(data1$pct_amred_forces_1991[!is.na(data1$pct_amred_forces_1991)]),
                             mean(data1$pct_amred_forces_1991, na.rm=T),
                             min(data1$pct_amred_forces_1991, na.rm=T), 
                             max(data1$pct_amred_forces_1991, na.rm=T), 
                             sd(data1$pct_amred_forces_1991, na.rm=T))



pct_amred_forces_2011 <-list("Pct. Armed Forces, 2001", length(data1$pct_amred_forces_2011[!is.na(data1$pct_amred_forces_2011)]),
                             mean(data1$pct_amred_forces_2011, na.rm=T),
                             min(data1$pct_amred_forces_2011, na.rm=T), 
                             max(data1$pct_amred_forces_2011, na.rm=T), 
                             sd(data1$pct_amred_forces_2011, na.rm=T))






sd<-as.data.frame(rbind(list_rat_medical_personel_1857,
                        list_railroads_1869_density,
                        list_thoroughfare_1940_density,
                        list_roads_1957_concrete_density,
                        pct_no_water,
                        pov_rate_income,
                        share_lesseduc_25,
                        log_existing_zadrugas_yokes,
                        prop_zadruga_from_total_area,
                        log_pop_zadrugas,
                        trust_people,
                        trust_family,
                        trust_foreign_investors,
                        trust_presidency,
                        bribery_road_police,
                        bribery_unempl,
                        part_demonstr,
                        sign_petition,
                        elevation,
                        slope,
                        tmp_mean_2010,
                        pre_mean_2010,
                        maizemed,
                        river_total,
                        river_density,
                        trade_route_1450_density,
                        trade_center_count,
                        migration_rate_1857,
                        migration_rate_1944,
                        migration_rate,
                        list_pct_serbs_1921,
                        list_pct_serbs_1931,
                        list_pct_serbs_1991,
                        list_pct_serbs_2001,
                        list_pct_change_serbs,
                        list_pct_serbs_2011,
                        list_pct_croats_1921,
                        list_pct_croats_1931,
                        list_pct_croats_1991,
                        list_pct_croats_2001,
                        list_pct_change_croats,
                        list_pct_croats_2011,
                        list_pct_priests_1857,
                        list_pct_civil_servants_1857))
colnames(sd)<-c("Variable", "N", "Mean", "Min", "Max", "SD")
rownames(sd) <- NULL

ncol(sd)
object_latex<-xtable(sd, type = "latex", caption = "Summary Statistics", digits=c(0,0,0,3,3,3,3))
align(object_latex) <- xalign(object_latex)

large <- function(x){
  paste0('{\\bfseries ', x, '}') }
italic <- function(x){ paste0('{\\emph{ ', x, '}}')
}

print(object_latex, file = "./Dropbox/Legacies_Project/Paper/tables/tableA1a.tex", 
      caption.placement = "top",
      sanitize.colnames.function = large,
      booktabs = TRUE,
      include.rownames=FALSE)



sd<-as.data.frame(rbind(list_pct_military_1857,
                        list_pct_lawyers_1857,
                        list_pct_doctors_1857,
                        list_pct_manufacturers_1857,
                        list_pct_merchants_1857,
                        list_pct_fishermen_1857,
                        list_pct_agriculture_1857,
                        list_pct_worker_crafts_1857,
                        list_pct_worker_trade_1857,
                        list_pct_day_workes_1857,
                        list_railroads_1869_density,
                        list_market_places,
                        list_planned_railroads_1869_density,
                        list_thoroughfare_1940_density,
                        list_roads_1957_concrete_density,
                        list_road_residential_density,
                        list_road_track_density,
                        log_ww2_bombs_no,
                        log_tons_TNT,
                        log_con_camp_no,
                        log_con_camp_prisoners,
                        log_massacre_death_no,
                        zadrugas_total,
                        households_with_no_zadruga_member,
                        coop_machines_plows_all_kinds,
                        q925a,
                        q925b,
                        q925c,
                        Sum_deaths,
                        Sum_buildings,
                        Sum_minor_dam_1,
                        Sum_light_dam_constr_2,
                        Sum_light_dam_port_3,
                        Sum_serious_dam_4,
                        Sum_build_part_destr_5,
                        Sum_build_compl_dam_6,
                        Sum_buildings,
                        Sum_church_faith_places,
                        Sum_schools_hotels,
                        Sum_monuments_symbols,
                        q924a,
                        q924c,
                        bosnia_distance,
                        road_density_2022,
                        eth_frac_1921,
                        eth_frac_1931,
                        eth_frac_1991,
                        eth_frac_2001,
                        eth_frac_2011,
                        transparency,
                        pct_amred_forces_1857,
                        pct_military_1900,
                        pct_military_1910,
                        pct_military_1930,
                        pct_amred_forces_1991,
                        pct_amred_forces_2011))
colnames(sd)<-c("Variable", "N", "Mean", "Min", "Max", "SD")
rownames(sd) <- NULL


ncol(sd)
object_latex<-xtable(sd, type = "latex", caption = "Summary Statistics (\\textit{Continued})", digits=c(0,0,0,3,3,3,3))
align(object_latex) <- xalign(object_latex)

large <- function(x){
  paste0('{\\bfseries ', x, '}') }
italic <- function(x){ paste0('{\\emph{ ', x, '}}')
}

print(object_latex, file = "./Dropbox/Legacies_Project/Paper/tables/tableA1b.tex", 
      caption.placement = "top",
      sanitize.colnames.function = large,
      booktabs = TRUE,
      include.rownames=FALSE)

